import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/page/train/teacher_work_course_list_page.dart';
import 'package:flutter_learn_vi/src/page/train/teacher_work_train_list_page.dart';
import 'package:get/get.dart';

import 'course_teacher_recoder_list_page.dart';

///教师的培训
class TeacherWorkMainPage extends StatefulWidget {
  const TeacherWorkMainPage({Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _TeacherWorkMainPageState();
  }
}

class _TeacherWorkMainPageState extends State<TeacherWorkMainPage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  List<String> assetList = [
    "assets/images/3.0x/teacher_icon1.png",
    "assets/images/3.0x/teacher_icon2.png",
    "assets/images/3.0x/teacher_icon3.png",
  ];
  List<String> textList = [
    "培训与签到",
    "课程安排",
    "签到记录",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("教师工作台"),
      ),
      body: Container(
        height: 180,
        width: MediaQuery.of(context).size.width,
        child: GridView.builder(
          itemCount: assetList.length,
          itemBuilder: (BuildContext context, int index) {
            return InkWell(
              child: buildClipRRect(index),
              onTap: () {
                Widget page;
                if (index == 0) {
                  page = TeacherWorkTrainListPage(
                    tag: 'maine',
                  );
                } else if (index == 1) {
                  page = TeacherWorkCourseListPage(
                    tag: 'maine',
                  );
                } else if (index == 2) {
                  page = CourseTeacherRecoderListPage(
                    tag: 'maine',
                  );
                }

                if (page != null) {
                  Get.to(() => page);
                }
              },
            );
          },
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            //纵轴间距
            mainAxisSpacing: 2.0,
            //横轴间距
            crossAxisSpacing: 2.0,
            //子组件宽高长度比例
            childAspectRatio: 1.1, crossAxisCount: 3,
          ),
        ),
      ),
    );
  }

  buildClipRRect(int index) {
    return Container(
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image.asset(
            assetList[index],
            width: 56,
            height: 56,
          ),
          Container(
            child: Text(textList[index]),
          )
        ],
      ),
    );
  }
}
